﻿using UnityEngine;
using System.Collections.Generic;
using Dict.DataModel;

namespace Dict.Blo
{
    public class DictFieldResourceBlo
    {
        static public List<TableFieldResource> GetAll()
        {
            return Dict.DictDataManager.Instance.tableFieldResourceDao.CacheList;
        }

        static public List<TableFieldResource> GetAllFish()
        {
            List<TableFieldResource> fishs = new List<TableFieldResource>();
            foreach(var fish in GetAll())
            {
                if(fish.id.StartsWith("group_fish_"))
                {
                    fishs.Add(fish);
                }
            }
            return fishs;
        }

        static public List<TableFieldResource> GetAllMine()
        {
            List<TableFieldResource> fishs = new List<TableFieldResource>();
            foreach (var fish in GetAll())
            {
                if (fish.id.StartsWith("group_mine_"))
                {
                    fishs.Add(fish);
                }
            }
            return fishs;
        }
        
        static public TableFieldResource GetOne(string id)
        {
            return Dict.DictDataManager.Instance.tableFieldResourceDao.GetById(id);
        }

        static public Dictionary<string,int> GetCost(string id)
        {
            Dictionary<string, int> dictCost = new Dictionary<string, int>();
            var res = GetOne(id);
            var costStr = res.cost;
            if(costStr.Contains(";"))
            {
                var str = costStr.Split(new char[1] { ';' },System.StringSplitOptions.RemoveEmptyEntries);
                foreach(var it in str)
                {
                    var ss = it.Split(new char[1] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
                    dictCost[ss[0]] = int.Parse(ss[1]);
                }
            }
            else
            {
                var ss = costStr.Split(new char[1] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
                dictCost[ss[0]] = int.Parse(ss[1]);
            }

            return dictCost;
        }
        
    }
}